package com.shoulder.launcher.launcher;

import com.shoulder.core.launcher.LauncherEnhancer;
import com.shoulder.launcher.listener.LauncherInitializedListener;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.ObjectUtils;

import java.util.Properties;
import java.util.ServiceLoader;

public class LauncherApplication {
    public static ConfigurableApplicationContext run(String appName, Class<?> source, String... args) {

        SpringApplication application = new SpringApplication(source);
        Properties properties = System.getProperties();
        properties.setProperty("spring.application.name", ObjectUtils.isEmpty(appName) ? "shoulder-platform" : appName);
        properties.setProperty("app-id", "shoulder");
        properties.setProperty("app-version", "forever");
        properties.setProperty("app-author", "596767880@qq.com");
        //添加运行时相关增强
        application.addListeners(new LauncherInitializedListener());
        //助力微服务添加启动参数
        ServiceLoader.load(LauncherEnhancer.class).forEach(LauncherEnhancer::enhance);
        return application.run(args);
    }

}
